<?php
    header('content-type: text/html; charset=utf-8');
    include_once 'DBLink.php';
    $method=$_REQUEST['method'];
    $dblink=new DBLink();
    switch ($method) {
        case 'add':
            $usrname=$_REQUEST['uname'];
            $usrpwd=$_REQUEST['upwd'];
            if($usrname=='' || $usrpwd==''){
                echo "<script>alert('账号或密码为空，请重新输入') ;</script>";
                header("refresh:1;url=../index.html");
            }
            else{
                $conn=$dblink->getConnect();
                $sql="SELECT uname FROM admin WHERE uname='$usrname'";
                if(mysqli_fetch_row($dblink->query($sql,$conn))){
                    session_start();
                    $_SESSION['uname']=$usrname;
                    $_SESSION['upwd']=$usrpwd;
                    echo "<script>alert('账号重复，请重新输入') ;</script>";
                   // header("refresh:1;url=../index.html");
                }
                else{
                    $sql="insert into admin(uname,upwd) values ('$usrname','$usrpwd')";
                    $conn=$dblink->getConnect();
                    $rel=$dblink->query($sql,$conn);
                    if($rel!=null){
                    echo "<script>alert('注册成功，请进行登陆')</script>";
                    header("refresh:1;url=../index.html");
                    }
                    else{
			    echo "<script>alert('注册失败，请重试')history.go(-1);</script>";
			    //header("refresh:1;url=../index.html");
                        }
                    $dblink->close($conn);
                }
            }
            break;
        default:
	    echo "<script>alert('数据出错') ;</script>";
            break;
    }

?>

